package com.zm.admin.im;

import com.zm.admin.annotation.SysLogTag;
import com.zm.admin.im.dto.ImMsgBody;
import com.zm.admin.im.dto.MsgDto;
import com.zm.admin.utils.ResultBean;
import com.zm.admin.zmeng.service.ZmAttachmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/***
 *
 * @Auther: MuYun
 * @Date: 2023/2/2 16:29
 * @Description： 聊天室相关接口
 *
 */
@RestController
@Slf4j
@RequestMapping("/im")
public class ImController {

    @Resource
    private ImService imService;

    /**
     * 获取消息页
     * @return
     */
    @RequestMapping("/online")
    public ResultBean online(){
        return imService.online();
    }

    /**
     * 获取聊天记录
     * @param userId
     * @return
     */
    @RequestMapping("/userClick")
    public ResultBean userClick(@RequestParam(value = "userId") String userId){
        return imService.userClick(userId);
    }

    /**
     * 发送消息
     * @param msgDto
     * @return
     */
    @SysLogTag(desc = "发送文字消息")
    @RequestMapping("/send")
    public ResultBean send(MsgDto msgDto){
        return imService.send(msgDto.getUserId(), msgDto.getMsg(), ImMsgBody.MsgType.text);
    }

    /**
     * 发送历史图片消息
     * @param msgDto
     * @return
     */
    @SysLogTag(desc = "发送历史图片消息")
    @RequestMapping("/sendImg")
    public ResultBean sendHisImg(MsgDto msgDto){
        return imService.send(msgDto.getUserId(), msgDto.getMsg(), ImMsgBody.MsgType.img);
    }

    /**
     * 发送图片消息
     * @param request
     * @param file
     * @param userId
     * @return
     */
    @SysLogTag(desc = "发送图片消息")
    @RequestMapping("/sendNewImg")
    public ResultBean sendNewImg(HttpServletRequest request, MultipartFile file,String userId){
        return imService.sendNewImg(request,file,userId);
    }

}
